package pbbltobpel.parser;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.predic8.wsdl.Definitions;

public class PddlPlan implements IXmlReader {
	private List<Fact> facts;
	private List<PlanStep> steps;
	private String fileName;
	private Hashtable<String, Definitions> wsdls;
	
	public PddlPlan() {
		facts = new ArrayList<Fact>();
		steps = new ArrayList<PlanStep>();
		wsdls = new Hashtable<String, Definitions>();
	}
	
	public List<PlanStep> getSteps() {
		return steps;
	}
	public void setSteps(List<PlanStep> steps) {
		this.steps = steps;
	}
	public List<Fact> getFacts() {
		return facts;
	}
	public void setFacts(List<Fact> facts) {
		this.facts = facts;
	}
	
	@Override
	public void getFromXmlElement(Element el) {
		NodeList factnodes = el.getElementsByTagName("facts").item(0).getChildNodes();
		for(int i = 0; i < factnodes.getLength(); i++) {
			Node node = factnodes.item(i);
			Fact fact = new Fact();
			fact.getFromXmlElement((Element)node);
			facts.add(fact);
		}
		NodeList stepsnodes = el.getElementsByTagName("plan").item(0).getChildNodes();
		for(int i = 0; i < stepsnodes.getLength(); i++) {
			Node node = stepsnodes.item(i);
			PlanStep step = new PlanStep();
			step.setPlan(this);
			step.getFromXmlElement((Element)node);
			steps.add(step);
		}
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public Hashtable<String, Definitions> getWsdls() {
		return wsdls;
	}

	public void setWsdls(Hashtable<String, Definitions> wsdls) {
		this.wsdls = wsdls;
	}
}
